package com.huopaolan.yohuoshop.Mvp.Presenter;

import com.huopaolan.lib_core.Mvp.Presenter.BasePresenter;
import com.huopaolan.yohuoshop.Bean.StrollCommunityEntity;
import com.huopaolan.yohuoshop.Mvp.Contract.CommunityFragmentContract;

import org.json.JSONException;
import org.json.JSONObject;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class StrollCommunityPresenter extends BasePresenter<CommunityFragmentContract.CommunityWriteIView, CommunityFragmentContract.CommunityWriteIModel> {
    @Inject
    public StrollCommunityPresenter(CommunityFragmentContract.CommunityWriteIView communityWiterIView, CommunityFragmentContract.CommunityWriteIModel communityWiterIModel) {
        super(communityWiterIView, communityWiterIModel);
    }

    /**
     * 请求数据
     */
    public void CommunityDataRequest() {
        JSONObject data = new JSONObject();
        try {
            data.put("page", "1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String request = data.toString();
        m.community_write_request(request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StrollCommunityEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StrollCommunityEntity communityEntity) {
                        v.CommunityWriteSuccess(communityEntity);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
